import {
  post
} from "../../utils/http";
Page({
  data: {
    background: [],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    circular: false,
    interval: 2000,
    duration: 500,
    previousMargin: 0,
    nextMargin: 0,
    newList: [],
    flag: true,
    isShow: false
  },
  pageSize: 10,
  pageNum: 1,
  goDetail(e) {
    wx.navigateTo({
      url: `../detail/detail?id=${e.currentTarget.dataset.articleId}`,
    })
  },
  onReady: function () {},
  onLoad: function (options) {
    post('https://showme2.myhope365.com/api/cms/article/open/banner/list', {
      pageNum: 1
    }).then(res => {
      this.setData({
        background: res.data.rows
      })
    })
    this.initData()

  },
  initData() {
    this.data.flag = false
    this.setData({
      flag: false
    })
    post('https://showme2.myhope365.com/api/cms/article/open/list', {
      pageNum: this.pageNum,
      pageSize: this.pageSize
    }).then(res => {
      this.data.newList = this.data.newList.concat(res.data.rows)
      this.setData({
        newList: this.data.newList
      })
      console.log(this.data.newList);


      this.handleList()

    })
  },
  handleList() {
    if (this.pageNum * this.pageSize >= this.data.total) {
      this.setData({
        flag: false,
        isShow: true
      })
      return
    } else {
      this.setData({
        flag: true
      })
      return
    }
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.flag) {
      this.pageNum++;
      this.initData()
    }

  },
  // 获取滚动条当前位置
  onPageScroll: function (e) {
    console.log(e)
    if (e.scrollTop > 100) {
      this.setData({
        floorstatus: true
      });
    } else {
      this.setData({
        floorstatus: false
      });
    }
  },

  //回到顶部
  goTop: function (e) { // 一键回到顶部
    if (wx.pageScrollTo) {
      wx.pageScrollTo({
        scrollTop: 0
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
      })
    }
  },

})